package com.helin.helinhealth.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * OpenAPI (Swagger) 配置类
 * 
 * <p>
 * 该配置类用于配置OpenAPI 3.0 (Swagger) 文档生成。
 * 文档可访问路径：http://localhost:8910/swagger-ui/index.html
 * 或者Knife4j增强UI：http://localhost:8910/doc.html
 * </p>
 */
@Configuration
public class OpenApiConfig {
    
    /**
     * OpenAPI基础配置
     * 
     * @return OpenAPI配置对象
     */
    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("鹤龄健康 API 文档")
                        .description("本文档提供鹤龄健康系统的API接口说明，供前端开发参考")
                        .version("v1.0.0")
                        .contact(new Contact()
                                .name("鹤龄健康开发团队")
                                .email("support@helinhealth.com")
                                .url("https://helinhealth.com"))
                        .license(new License().name("私有许可").url("https://helinhealth.com/license")))
                // 添加JWT认证配置
                .addSecurityItem(new SecurityRequirement().addList("Bearer Authentication"))
                .components(new Components()
                        .addSecuritySchemes("Bearer Authentication", createAPIKeyScheme()));
    }
    
    /**
     * 创建API密钥认证方案
     * 
     * @return 安全方案定义
     */
    private SecurityScheme createAPIKeyScheme() {
        return new SecurityScheme()
                .type(SecurityScheme.Type.HTTP)
                .bearerFormat("JWT")
                .scheme("bearer");
    }
} 